package com.ruoyi.develop.projectInvoiceInfo.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.develop.projectBaseInfo.domain.ProjectBaseInfo;
import com.ruoyi.develop.projectBaseInfo.service.IProjectBaseInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.projectInvoiceInfo.domain.ProjectInvoiceInfo;
import com.ruoyi.develop.projectInvoiceInfo.service.IProjectInvoiceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目开票信息管理Controller
 * @author qh
 * @date 2023-01-10
 */
@RestController
@RequestMapping("/projectInvoiceInfo/projectInvoiceInfo")
public class ProjectInvoiceInfoController extends BaseController {
    @Autowired
    private IProjectInvoiceInfoService projectInvoiceInfoService;

    /**
     * 查询项目开票信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('develop:ProjectInvoiceInfo:query')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectInvoiceInfo entity) {
        startPage();
        List<ProjectInvoiceInfo> list = projectInvoiceInfoService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出项目开票信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('develop:ProjectInvoiceInfo:export')")
    @Log(title = "项目开票信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectInvoiceInfo entity) {
        List<ProjectInvoiceInfo> list = projectInvoiceInfoService.selectList(entity);
        ExcelUtil<ProjectInvoiceInfo> util = new ExcelUtil<ProjectInvoiceInfo>(ProjectInvoiceInfo. class);
        util.exportExcel(response, list, "项目开票信息管理数据");
    }

    /**
     * 获取项目开票信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:ProjectInvoiceInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(projectInvoiceInfoService.selectById(id));
    }

    /**
     * 新增项目开票信息管理
     */
    @PreAuthorize("@ss.hasPermi('develop:ProjectInvoiceInfo:add')")
    @Log(title = "项目开票信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProjectInvoiceInfo entity) {
        if(entity.getInvoiceMoney().compareTo(BigDecimal.ZERO)!=0){
            int i = projectInvoiceInfoService.insert(entity);
            return toAjax(i);
        }else {
            return AjaxResult.error("发票金额不能为0");
        }
    }

    /**
     * 修改项目开票信息管理
     */
    @PreAuthorize("@ss.hasPermi('develop:ProjectInvoiceInfo:edit')")
    @Log(title = "项目开票信息管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ProjectInvoiceInfo entity) {
        return toAjax(projectInvoiceInfoService.update(entity));
    }

    /**
     * 修改项目开票信息管理
     */
    @Log(title = "项目开票信息核销处理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit0704")
    public AjaxResult edit0704(@RequestBody ProjectInvoiceInfo entity) {
        return toAjax(projectInvoiceInfoService.update0704(entity));
    }

    /**
     * 删除项目开票信息管理
     */
    @PreAuthorize("@ss.hasPermi('develop:ProjectInvoiceInfo:remove')")
    @Log(title = "项目开票信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        int i = projectInvoiceInfoService.deleteByIds(ids);

        return toAjax(i);
    }
}
